//
//  HMCollectionCell.swift
//  swift一遍敲
//
//  Created by 刘耀宗 on 16/4/20.
//  Copyright © 2016年 刘耀宗. All rights reserved.
//

import UIKit

class HMCollectionCell: UICollectionViewCell {
    
    var imageName: String?
        {
        didSet
        {
            self.cellImageView.image = UIImage(named: imageName!)
        
            //隐藏
            newFeatureBtn.hidden = true
        }
    
    
    }
    
        override init(frame: CGRect) {
            super.init(frame: frame)
            prepareUI()
           
        }
    private func  prepareUI(){
    contentView.addSubview(cellImageView)
        contentView.addSubview(newFeatureBtn)
        
    
        
        
    
    
    }
    //执行动画
    func startAnimation()
    {
        //缩小为0
        newFeatureBtn.hidden = false
        newFeatureBtn.transform = CGAffineTransformMakeScale(0, 0)
        
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            
            self.newFeatureBtn.transform = CGAffineTransformIdentity  // 清空transform的缩放, 1
        }) { (_) -> Void in
            print("动画完成了")
        }
        
    
    
    
    }
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
        //懒加载
        private lazy var cellImageView: UIImageView = {
            let cellImage = UIImageView()
            cellImage.image = UIImage(named: "new_feature_1")
            
            
            return cellImage
            
        }()
     lazy var newFeatureBtn: UIButton = {
        let btn = UIButton()
        btn.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "new_feature_finish_button_highlighted"), forState: UIControlState.Highlighted)
        btn.setTitle("进入", forState: UIControlState.Normal)
       btn.sizeToFit()
        btn.addTarget(self, action: #selector(HMCollectionCell.clickBtn), forControlEvents: UIControlEvents.TouchUpInside)
        return btn
    
    
    }()
    @objc private func clickBtn()
    {
    
        UIApplication.sharedApplication().delegate?.window!!.rootViewController = HMMainTabbarVC()
    
    }
    
    
        override func layoutSubviews() {
            super.layoutSubviews()
            //设置约束
            cellImageView.snp_makeConstraints { (make) in
                make.edges.equalTo(self)
            }
            newFeatureBtn.snp_makeConstraints { (make) in
                make.width.equalTo(80)
                make.height.equalTo(37)
                make.centerX.equalTo(self)
                make.bottom.equalTo(self.snp_bottom).offset(-50)
            }

    
        }
        



}
